﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.Read.API.Appicant.Command.TrunMeonCommand;
using MediatR;

namespace B.S.DataBase.Read.API.Appicant.CommandHandler.TrunMeonCommandHandler
{
    public class GetMeonCommandHandler : IRequestHandler<GetMeonCommand, APIResult<List<User>>>
    {
        /// <summary>
        /// 查询用户部门的管理者
        /// </summary>
        private readonly IBaseRepository<User> baseRepository;

        public GetMeonCommandHandler(IBaseRepository<User> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<List<User>>> Handle(GetMeonCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<User>> result  =new APIResult<List<User>>();
            result.Code = APIEnum.查询成功;
            result.Msg =APIEnum.查询成功.ToString();

            var lsit = baseRepository.GetAll().Result.Where(x => x.DepId >= request.DepId && x.Weight == request.Weight);


            result.data = lsit.ToList();

            return Task.FromResult(result);

            
        }
    }
}
